#!/bin/sh
let_time=$(date "+%Y%m%d")

imageTag="micro"
projectName="micro-auth"
envName="pro"
gatewayHostPort="120.48.119.105:9000"
#配置中心命令空间，如果没有配置中心，可把这个配置设置为空，如下
nacosConfigNamespace=""
#nacosConfigNamespace=" -e NACOS_CONFIG_NAMESPACE=698ef0a6-76c3-4cf8-880b-91baa0bf06c5 "

#配置注册到nacos的ip，方便本地微服务调试，一般设置为服务部署的服务器外网ip
#nacosDiscoveryIp=""
nacosDiscoveryIp=" -e SPRING_CLOUD_NACOS_DISCOVERY_IP=121.36.20.90 "

cd /root/dockerfile/${envName}/${projectName}/

`curl http://${gatewayHostPort}/service/down/${projectName}-${envName}`

containerName=$(docker ps -a|grep ${projectName}-${envName}|awk '{print $1}')
if [ "$containerName" != "" ] ; then
echo 删除容器 $containerName ...
docker rm -f $containerName
fi
echo 删除镜像
docker rmi -f ${imageTag}/${projectName}:${envName}
echo 运行新的容器 ...

docker build -t ${imageTag}/${projectName}:${envName} .

# 后端  -e SPRING_APPLICATION_NAME=micro-auth-pro
docker run -d -t -p 9081:9081 -p 19081:19081 \
-v /etc/localtime:/etc/localtime:ro \
-v /data/micro-logs/auth:/logs \
-e SERVER_PORT=9081 \
-e JAVA_OPTS="-Xms256m -Xmx512m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=19081" \
-m 1G -e PROFILE_ACTIVE=${envName} -e NACOS_HOST=120.48.119.105 ${nacosDiscoveryIp} \
${nacosConfigNamespace} -e REDIS_HOST=120.48.119.106 -e REDIS_DB="12" -e REDIS_PASS=2022 \
-e MYSQL_URL="jdbc:mysql://192.168.0.250:3306/osdp?characterEncoding=UTF-8&useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghai" \
-e MYSQL_PASS='ztlb_21640705' --name ${projectName}-${envName} ${imageTag}/${projectName}:${envName}
